package com.backstage.service.Impl;

import com.backstage.mapper.SysUserInfoMapper;
import com.backstage.pojo.dto.Message;
import com.backstage.pojo.entity.SysRole;
import com.backstage.pojo.entity.SysUserInfo;
import com.backstage.service.SysUserInfoService;
import com.backstage.util.PojoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("SysUserInfoService")
public class SysUserInfoServiceImpl implements SysUserInfoService {
    @Autowired
    SysUserInfoMapper userInfoMapper;

    @Override
    public Message<List<SysUserInfo>> userInfoList(SysUserInfo userInfos) {

        return null;
    }

    @Override
    public Message<SysUserInfo> selectOne(SysUserInfo userInfo) {
        return null;
    }

    /**
     * @param userInfo
     * @return
     */
    @Override
    public Message<SysUserInfo> addRole(SysUserInfo userInfo) {
        //判断传入参数是否为空
        if (userInfo == null) return Message.errorMessage("1002", "用户信息为空");
        int insert = userInfoMapper.insert(userInfo);
        if (insert == 0) {
            return Message.errorMessage("1001", "用户信息添加失败");
        } else {
            return Message.successMessage(1L, userInfo);
        }

    }

    /**
     * @param userInfo
     * @return
     */
    @Override
    public Message<SysUserInfo> updateRole(SysUserInfo userInfo) {
        //判断传入参数是否为空
        if (userInfo == null) return Message.errorMessage("1002", "用户信息未接收");

        int insert = userInfoMapper.updateById(userInfo);
        if (insert == 0) {
            return Message.errorMessage("1001", "用户信息修改失败");
        } else {
            return Message.successMessage(1L, userInfo);
        }
    }

    @Override
    public Message<String> deleteRole(Long id) {
        int delete = userInfoMapper.deleteById(id);
        if (delete == 0) {
            return Message.errorMessage("1001", "用户信息删除失败");
        } else {
            return Message.successMessage(1L, "删除成功");
        }
    }

    @Override
    public Message<String> deleteRoleList(List<Long> userInfos) {
        for (int i = 0; i < userInfos.size(); i++) {
            Long aLong = userInfos.get(i);
            deleteRole(aLong);
        }
        return Message.successMessage(1L, "已经全部删除成功");
    }
}
